

// 比较obj 属性排序
var compare = function (prop){
 
 return function(obj1,obj2){
      
      var val1 = obj1[prop];
      var val2 =  obj2[prop];

      if (val1<val2) {
      	return -1     //降序
      }else if (val1>val2) {
      	return 1
      }else{
      	return 0 
      }

 }

}



function angleBetweenThreePoints(centerx,centery,p1x,p1y,p2x,p2y){
 
 var center = {x:centerx,y:centery}
 var p1 = {x:p1x,y:p1y}
 var p2 = {x:p2x,y:p2y}

 var v1 = {x:p1.x -center.x ,y:p1.y - center.y}
 var  v2  = {x:p2.x -center.x ,y:p2.y - center.y}

 var angle = Math.atan2(v2.x*v1.y - v1.x * v2.y,v1.x*v2.x + v1.y * v2.y)
 result = 180.0 * angle / Math.PI
 return  -result


}












module.exports = {
 compare:compare,
 angleBetweenThreePoints:angleBetweenThreePoints
}



